package com.naihe.anderson.sms.widgets;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.naihe.anderson.sms.R;
import com.naihe.anderson.sms.activity.MakeNewMessageActivity;
import com.naihe.anderson.sms.activity.TalkMessageActivity;
import com.naihe.anderson.sms.adapter.HorizontalSmsAdapter;
import com.naihe.anderson.sms.entity.NhsmsSession;
import com.naihe.anderson.sms.listener.OnMenuDialogClickListener;

public class DragGrid extends GridView {

	OnMenuDialogClickListener onMenuDialogClickListener;
	public DragGrid(Context context, AttributeSet attrs, Handler mHandler) {
		super(context, attrs);
	}

	public DragGrid(Context context,OnMenuDialogClickListener listener) {
		super(context);
		onMenuDialogClickListener = listener;
		init();
	}
	
	public void init(){
		this.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id) {
				NhsmsSession nhsmsSession = ((HorizontalSmsAdapter)parent.getAdapter()).getItem(position);
				if(nhsmsSession != null){
					new MenuDialog(getContext(), R.style.dialogStyle, onMenuDialogClickListener, nhsmsSession).show();
				}
				return false;
			}
		});
		this.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				NhsmsSession nhsmsSession = ((HorizontalSmsAdapter)parent.getAdapter()).getItem(position);
				if(nhsmsSession != null){
					Intent intent = new Intent(getContext(), TalkMessageActivity.class);
					intent.putExtra("NhsmsSession", nhsmsSession);
					getContext().startActivity(intent);
				} else {
					Intent intent = new Intent(getContext(), MakeNewMessageActivity.class);
					getContext().startActivity(intent);
				}
			}
		});
	}
}















